/*
 * UMLSynch plugin for Eclipse-CDT
 * http://umlsynch.googlecode.com
 *
 * Copyright 2008-2010, Evgeny Alexeyev
 * Licensed under the EPL - v1.0
 * http://www.eclipse.org/legal/epl-v10.html
 *
 */

package com.googlecode.umlsynch.eclipse.IndexFilters;

import org.eclipse.cdt.core.dom.ast.DOMException;
import org.eclipse.cdt.core.dom.ast.IBinding;
import org.eclipse.cdt.core.dom.ast.IParameter;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBase;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.index.IndexFilter;

public class HasClassReferenceFromMethodsIndexFilter extends IndexFilter {
	public String classReference = null;
	
	public boolean acceptBinding(IBinding binding) {
		if (classReference == null)
			return false;

		if (binding instanceof ICPPClassType) {
			ICPPClassType classType = (ICPPClassType)binding;
			try {
				ICPPMethod[] meths =  classType.getMethods();
				if (meths == null|| meths.length < 1)
					return false;
				
				for (int t=0; t < meths.length; t++){
					IParameter[] pars = meths[t].getParameters();
					if (pars != null && pars.length > 0)
						for (int tt=0; tt < pars.length; tt++){
							if (pars[tt].getType().toString().contains(classReference))
								return true;
						}
				}
					
				//ICPPMethod[] methods = classType.getDeclaredFields();
			} catch (DOMException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}						
		}
		return false;
	}
}
